package com.tencreat.mall.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencreat.common.annotation.Log;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.common.core.domain.AjaxResult;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.common.enums.BusinessType;
import com.tencreat.common.utils.poi.ExcelUtil;
import com.tencreat.domain.mall.MallSignIn;
import com.tencreat.service.mall.IMallSignInService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 签到配置Controller
 *
 * @author tencreat
 * @date 2022-01-17
 */
@Api(tags="签到配置api")
//@RestController
@RequestMapping("/mall/in")
public class AdminMallSignInController extends BaseController {
    //@Autowired
    private IMallSignInService mallSignInService;

    /**
     * 查询签到配置列表
     */
    @ApiOperation(value="查询签到配置列表")
    @PreAuthorize("@ss.hasPermi('system:in:list')")
    @PostMapping("/list")
    public HttpResult<IPage<MallSignIn>> list(@RequestBody  MallSignIn mallSignIn) {
        QueryWrapper<MallSignIn> wrapper = Wrappers.query(mallSignIn);
        Page<MallSignIn> page =  new Page<>(mallSignIn.getPageNum(), mallSignIn.getPageSize());
        return HttpResult.ok(mallSignInService.page(page, wrapper));
    }

    /**
     * 导出签到配置列表
     */
    @ApiOperation(value="导出签到配置列表")
    @PreAuthorize("@ss.hasPermi('system:in:export')")
    @Log(title = "营销管理>签到配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(MallSignIn mallSignIn) {
        List<MallSignIn> list = mallSignInService.selectMallSignInList(mallSignIn);
        ExcelUtil<MallSignIn> util = new ExcelUtil<MallSignIn>(MallSignIn.class);
        return util.exportExcel(list, "in");
    }

    /**
     * 获取签到配置详细信息
     */
    @ApiOperation(value="获取签到配置详细信息")
    @PreAuthorize("@ss.hasPermi('system:in:query')")
    @PostMapping(value = "/getInfo")
    public HttpResult<MallSignIn> getInfo(@RequestBody   ReqIdParam id) {
        return HttpResult.ok(mallSignInService.selectMallSignInById(id));
    }

    /**
     * 新增签到配置
     */
    @ApiOperation(value="新增签到配置")
    @PreAuthorize("@ss.hasPermi('system:in:add')")
    @Log(title = "营销管理>签到配置", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public HttpResult<Boolean> add(@RequestBody  MallSignIn mallSignIn) {
        return to(mallSignInService.insertMallSignIn(mallSignIn));
    }

    /**
     * 修改签到配置
     */
    @ApiOperation(value="修改签到配置")
    @PreAuthorize("@ss.hasPermi('system:in:edit')")
    @Log(title = "营销管理>签到配置", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public HttpResult<Boolean> edit(@RequestBody  MallSignIn mallSignIn) {
        return to(mallSignInService.updateMallSignIn(mallSignIn));
    }

    /**
     * 删除签到配置
     */
    @ApiOperation(value="删除签到配置")
    @PreAuthorize("@ss.hasPermi('system:in:remove')")
    @Log(title = "营销管理>签到配置", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
    public HttpResult<Boolean> remove(@RequestBody  ReqIdsParam ids) {
        return to(mallSignInService.deleteMallSignInByIds(ids));
    }
}
